<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>参数修改题生成器</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 30px auto;
            max-width: 800px;
            /* 修改背景属性 */
            background: linear-gradient(135deg, #a4faa9 0%, #a77b9a 100%);
            color: #333;
        }

        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 20px;
        }

        .question-counter {
            font-weight: bold;
            color: #1976D2;
            margin-bottom: 10px;
            text-align: center;
        }

        .timer {
            font-weight: bold;
            color: #d32f2f;
            margin-bottom: 15px;
            text-align: center;
        }

        .question-container {
            margin-bottom: 20px;
            padding: 20px;
            border: 2px solid #2980b9;
            border-radius: 10px;
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .question-container h3 {
            color: #2c3e50;
            margin-bottom: 15px;
        }

        .data-group {
            margin-bottom: 15px;
            display: flex;
            align-items: center;
        }

        .data-group strong {
            margin-right: 10px;
        }

        .input-group {
            margin-top: 15px;
            display: flex;
            align-items: center;
        }

        .input-group strong {
            margin-right: 10px;
        }

        input {
            margin-right: 10px;
            width: 80px;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            padding: 10px 20px;
            margin-right: 10px;
            background-color: #2980b9;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #2471a3;
        }

        button:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }

        .history {
            margin-top: 30px;
            border-top: 2px solid #333;
            padding-top: 15px;
        }

        .history h2 {
            color: #2c3e50;
            margin-bottom: 15px;
        }

        .history-item {
            margin-bottom: 15px;
            padding: 15px;
            background-color: #fff;
            border-radius: 5px;
            border-left: 5px solid #2980b9;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .correct {
            color: #27ae60;
        }

        .incorrect {
            color: #e74c3c;
        }
    </style>
</head>
<body>
    
    <h1>参数修改题生成器</h1>
    <div class="question-counter">当前题目: <span id="current-count">1</span></div>
    <div class="timer">剩余时间: <span id="time-left">30</span>秒</div>
    
    <div id="question-container" class="question-container">
        <h3>题目 <span id="question-number">1</span></h3>
        <div class="data-group">
            <strong>标片值:</strong> 
            ETA=<span id="eta1">0.000</span>, 
            ISC=<span id="isc1">0.000</span>, 
            UOC=<span id="uoc1">0.0000</span>, 
            FF=<span id="ff1">0.00</span>
        </div>
        <div class="data-group">
            <strong>对切值:</strong> 
            ETA=<span id="eta2">0.000</span>, 
            ISC=<span id="isc2">0.000</span>, 
            UOC=<span id="uoc2">0.0000</span>, 
            FF=<span id="ff2">0.00</span>
        </div>
        <div class="data-group">
            <strong>模拟值:</strong> 
            ETA=<span id="eta3">0.000</span>, 
            ISC=<span id="isc3">0.000</span>, 
            UOC=<span id="uoc3">0.0000</span>, 
            FF=<span id="ff3">0.00</span>
        </div>
        <div class="input-group">
            <strong>修正系数:</strong>
			FF系数: <input type="number" id="z" step="0.01" value="1.00">,
			uoc系数: <input type="number" id="y" step="0.01" value="1.00">,
            isc系数: <input type="number" id="x" step="0.01" value="1.00">
            
            
        </div>
        <div class="button-group">
            <button id="submit-btn">提交</button>
            <button id="next-btn">下一题</button>
        </div>
        <div id="result" style="margin-top: 10px;"></div>
    </div>
    
    <div class="history">
        <h2>历史记录</h2>
        <div id="history-container"></div>
    </div>

    <script>
        // 存储历史记录和当前题目数据
        const history = [];
        let currentQuestion = 1;
        let timerInterval;
        let timeLeft = 500; // 初始时间（秒）
        let currentParams = {};
        let originalCorrections = { x: 1, y: 1, z: 1 };
        let isSubmitted = false;
        const totalQuestions = 20; // 总题目数量
        let totalTimeUsed = 0; // 新增：总用时
        
        // 生成随机数函数
        function getRandomFloat(min, max, decimals = 2) {
            const str = (Math.random() * (max - min) + min).toFixed(decimals);
            return parseFloat(str);
        }
        
        // 根据关系计算其他参数
        function calculateParams(isc,uoc,ff) {
            return {
                ISC: isc,
                FF: ff,
                UOC: uoc,
                ETA: isc*uoc*ff/38.184
            };
        }
        
        // 生成一道题目
        function generateQuestion() {
            // 生成基准ETA值（对切值）
			const isc1 = getRandomFloat(15.8, 16.0,3);
			const uoc1 = getRandomFloat(0.7321, 0.7567,4);
			const ff1 = getRandomFloat(82.5, 83.5,2);
            const eta1 = (isc1*uoc1*ff1)/38.184;
            const params1 = calculateParams(isc1,uoc1,ff1);
            
            // 生成测试ETA值（与基准值有差异）
            const isc2 = isc1+getRandomFloat(-0.04, 0.04,3);
			const uoc2 = uoc1+getRandomFloat(-0.002, 0.002,4);
			const ff2 = ff1+getRandomFloat(-0.2, 0.2,2);
            const params2 = calculateParams(isc2,uoc2,ff2);
            
            return {
                params1,
                params2
            };
        }
        
        // 显示当前题目
        function displayQuestion() {
            const question = generateQuestion();
            currentParams = question;
            isSubmitted = false;
            // 记录初始修正系数
            originalCorrections = {
                x: 15.612+getRandomFloat(-0.5, 0.5,3),
                y: parseFloat((11.800+getRandomFloat(-0.5, 0.5,3)).toFixed(2) + '0'),
                z: parseFloat((-0.86+getRandomFloat(-0.2, 0.2,3)).toFixed(2) + '0'),
            };
            // 更新显示
            document.getElementById('eta1').textContent = question.params1.ETA.toFixed(3);
            document.getElementById('isc1').textContent = question.params1.ISC.toFixed(3);
            document.getElementById('uoc1').textContent = question.params1.UOC.toFixed(4);
            document.getElementById('ff1').textContent = question.params1.FF.toFixed(2);
            
            document.getElementById('eta2').textContent = question.params2.ETA.toFixed(3);
            document.getElementById('isc2').textContent = question.params2.ISC.toFixed(3);
            document.getElementById('uoc2').textContent = question.params2.UOC.toFixed(4);
            document.getElementById('ff2').textContent = question.params2.FF.toFixed(2);
            
            // 重置模拟值和修正系数
            document.getElementById('eta3').textContent = "0.000";
            document.getElementById('isc3').textContent = "0.000";
            document.getElementById('uoc3').textContent = "0.0000";
            document.getElementById('ff3').textContent = "0.00";
            
            document.getElementById('x').value = originalCorrections.x.toFixed(3);
            document.getElementById('y').value = originalCorrections.y.toFixed(2);
            document.getElementById('z').value = originalCorrections.z.toFixed(2);


            
            document.getElementById('result').innerHTML = "";
            
            
            
            // 重置提交按钮状态
            document.getElementById('submit-btn').disabled = false;
            document.getElementById('submit-btn').textContent = "提交";
            
            // 更新题目编号
            document.getElementById('question-number').textContent = currentQuestion;
            document.getElementById('current-count').textContent = `${currentQuestion}/${totalQuestions}`;
            
            // 重置计时器
            resetTimer();
        }
        
        // 定义一个变量来存储 5 秒定时器的 ID
        let autoNextQuestionTimer;
        
        // 计算模拟值
        function calculateSimulatedValues(kkk=true) {
            const currentCorrections = {
                x: parseFloat(document.getElementById('x').value),
                y: parseFloat(document.getElementById('y').value),
                z: parseFloat(document.getElementById('z').value)
            };
            
            // 计算模拟值 = 测试值 * 修正系数
           
            const isc3 = currentParams.params2.ISC -(currentCorrections.x-originalCorrections.x)/0.008*0.0062;
            const uoc3 = currentParams.params2.UOC +(currentCorrections.y-originalCorrections.y)/0.15*0.0003;
            const ff3 = currentParams.params2.FF +(currentCorrections.z-originalCorrections.z)/0.02*0.032;
            const eta3 = isc3*uoc3*ff3/38.184;
            
            // 更新显示
            document.getElementById('eta3').textContent = eta3.toFixed(3);
            document.getElementById('isc3').textContent = isc3.toFixed(3);
            document.getElementById('uoc3').textContent = uoc3.toFixed(4);
            document.getElementById('ff3').textContent = ff3.toFixed(2);
            
            // 计算准确率（ETA差值）
            const etaDiff = Math.abs(eta3 - currentParams.params1.ETA);
            const iscDiff = Math.abs(isc3 - currentParams.params1.ISC);
            const uocDiff = Math.abs(uoc3 - currentParams.params1.UOC);
            const ffDiff = Math.abs(ff3 - currentParams.params1.FF);
            const isCorrect1 = etaDiff < 0.03;
            const isCorrect2 = iscDiff < 0.03;
            const isCorrect3 = uocDiff < 0.0015;
            const isCorrect4 = ffDiff < 0.5;
            let isCorrect = true;
            // 显示结果
            const resultDiv = document.getElementById('result');
            if (isCorrect1 && isCorrect2 && isCorrect3 && isCorrect4) {
                resultDiv.innerHTML = `<span class="correct">正确！差值: ${etaDiff.toFixed(3)} < 0.03</span>`;
                
            } else {
                
                resultDiv.innerHTML = `<span class="incorrect">错误！差值: ${etaDiff.toFixed(3)} >= 0.02</span>`;
                isCorrect = false;
            }
            
            // 保存到历史记录
            saveToHistory(currentCorrections, isCorrect, etaDiff,iscDiff,uocDiff,ffDiff);
            
            // 标记为已提交
            isSubmitted = true;
            if(kkk==true){
                // 5秒后自动进入下一题
            autoNextQuestionTimer = setTimeout(() => {
                if (currentQuestion < totalQuestions) {
                    currentQuestion++;
                    if (currentQuestion == totalQuestions) {
                        document.getElementById('next-btn').disabled = true;
                    }
                    displayQuestion();
                } else {
                    alert("已完成所有" + totalQuestions + "道题目！");
                    document.getElementById('next-btn').disabled = true;
                    document.getElementById('submit-btn').disabled = true;
                    clearInterval(timerInterval);
                
                    // 计算得分
                    const correctCount = history.filter(item => item.isCorrect).length;
                    const score = (correctCount / totalQuestions) * 100;
                
                    const scoreElement = document.createElement('div');
                    scoreElement.textContent = `你的得分: ${score} 分（满分 100 分），总用时: ${totalTimeUsed} 秒`;
                    scoreElement.style.fontWeight = 'bold';
                    scoreElement.style.marginBottom = '15px';
                
                    // 将得分元素插入到历史记录容器之前
                    const historyContainer = document.getElementById('history-container');
                    const historyTitle = document.querySelector('.history h2');
                    historyTitle.insertAdjacentElement('afterend', scoreElement);
                
                    // 创建继续练题的按钮
                    const continueButton = document.createElement('button');
                    continueButton.textContent = "继续练题";
                    continueButton.addEventListener('click', function() {
                        this.remove(); // 移除继续练题按钮
                        document.getElementById('next-btn').disabled = false;
                        document.getElementById('submit-btn').disabled = false;
                        restartQuestions();
                        totalTimeUsed = 0; // 重置总用时
                        // 移除得分元素
                        scoreElement.remove();
                    });
                    
                    // 将继续练题按钮插入到得分元素之后
                    scoreElement.insertAdjacentElement('afterend', continueButton);
                }
            }, 5000);
            }
            
        
            return isCorrect;
        }
        
        // 保存到历史记录
        function saveToHistory(currentCorrections, isCorrect, etaDiff,iscDiff,uocDiff,ffDiff) {
            const timestamp = new Date().toLocaleTimeString();
            // 修正本题用时的计算逻辑，使用初始时间减去剩余时间
            const timeUsed = timeLeft - timeLefts;
            totalTimeUsed += timeUsed; // 累加总用时
            const historyItem = {
                timestamp,
                questionNumber: currentQuestion,
                params1: currentParams.params1,
                params2: currentParams.params2,
                simulatedValues: {
                    ETA: parseFloat(document.getElementById('eta3').textContent),
                    ISC: parseFloat(document.getElementById('isc3').textContent),
                    UOC: parseFloat(document.getElementById('uoc3').textContent),
                    FF: parseFloat(document.getElementById('ff3').textContent)
                },
                originalCorrections,
                currentCorrections,
                isCorrect,
                etaDiff,
                iscDiff,
                uocDiff,
                ffDiff,
                timeUsed
            };
            
            history.push(historyItem);
            updateHistoryDisplay();
        }
        
        // 更新历史记录显示
        function updateHistoryDisplay() {
            const historyContainer = document.getElementById('history-container');
            historyContainer.innerHTML = '';
            
            // 按时间倒序显示
            [...history].reverse().forEach(item => {
                const historyItem = document.createElement('div');
                historyItem.className = 'history-item';
                
                const statusClass = item.isCorrect ? 'correct' : 'incorrect';
                const statusText = item.isCorrect ? '正确' : '错误';
                
                historyItem.innerHTML = `
                    <strong>${item.timestamp} - 题目 ${item.questionNumber} (用时: ${item.timeUsed}秒, <span class="${statusClass}">${statusText}</span>, Eta差值: <span style="${item.etaDiff > 0.03 ? 'color: red' : ''}">${item.etaDiff.toFixed(3)}</span>, Isc差值: <span style="${item.iscDiff > 0.03 ? 'color: red' : ''}">${item.iscDiff.toFixed(3)}</span>, Uoc差值: <span style="${item.uocDiff > 0.0015 ? 'color: red' : ''}">${item.uocDiff.toFixed(4)}</span>, FF差值: <span style="${item.ffDiff > 0.5 ? 'color: red' : ''}">${item.ffDiff.toFixed(2)}</span>)</strong>
                    <div class="data-group">
                        <strong>标片值:</strong> 
                        ETA=${item.params1.ETA.toFixed(3)}, 
                        ISC=${item.params1.ISC.toFixed(3)}, 
                        UOC=${item.params1.UOC.toFixed(4)}, 
                        FF=${item.params1.FF.toFixed(2)}
                    </div>
                    <div class="data-group">
                        <strong>对切值:</strong> 
                        ETA=${item.params2.ETA.toFixed(3)}, 
                        ISC=${item.params2.ISC.toFixed(3)}, 
                        UOC=${item.params2.UOC.toFixed(4)}, 
                        FF=${item.params2.FF.toFixed(2)}
                    </div>
                    <div class="data-group">
                        <strong>模拟值:</strong> 
                        ETA=${item.simulatedValues.ETA.toFixed(3)}, 
                        ISC=${item.simulatedValues.ISC.toFixed(3)}, 
                        UOC=${item.simulatedValues.UOC.toFixed(4)}, 
                        FF=${item.simulatedValues.FF.toFixed(2)}
                    </div>
                    <div class="data-group">
                        <strong>修正系数(原):</strong> 
                        isc系数=${item.originalCorrections.x.toFixed(3)}, 
                        uoc系数=${item.originalCorrections.y.toFixed(3)}, 
                        ff系数=${item.originalCorrections.z.toFixed(3)}
                    </div>
                    <div class="data-group">
                        <strong>修正系数(改):</strong> 
                        isc系数=${item.currentCorrections.x.toFixed(3)}, 
                        uoc系数=${item.currentCorrections.y.toFixed(3)}, 
                        ff系数=${item.currentCorrections.z.toFixed(3)}
                    </div>
                `;
                
                historyContainer.appendChild(historyItem);
            });
        }
        
        // 启动计时器
        function startTimer() {
            clearInterval(timerInterval);
            timeLefts = timeLeft;
            document.getElementById('time-left').textContent = timeLefts;
            
            timerInterval = setInterval(() => {
                timeLefts--;
                document.getElementById('time-left').textContent = timeLefts;
                
                if (timeLefts <= 0) {
                    clearInterval(timerInterval);
                    // 如果未提交，自动提交
                    if (!isSubmitted) {
                        calculateSimulatedValues();
                    }
                    // 自动下一题（如果还有题目）
                    if (currentQuestion < totalQuestions) {
                        currentQuestion++;
                        if(currentQuestion==totalQuestions){
                            document.getElementById('submit-btn').disabled = true;
                }
                        displayQuestion();
                    } else {
                        alert("已完成所有20道题目！");
						clearInterval(timerInterval);
                    }
                }
            }, 1000);
        }
        
        // 重置计时器
        function resetTimer() {
            startTimer();
        }
        
        // 事件监听
        document.getElementById('submit-btn').addEventListener('click', function() {
            // 禁用提交按钮，防止重复提交
            this.disabled = true;
            this.textContent = "已提交";
            
            // 获取当前修正系数
            const currentCorrections = {
                x: parseFloat(document.getElementById('x').value),
                y: parseFloat(document.getElementById('y').value),
                z: parseFloat(document.getElementById('z').value)
            };
            
            // 计算模拟值并保存记录
            calculateSimulatedValues();
        });
        // 下一题按钮点击事件
        document.getElementById('next-btn').addEventListener('click', function() {
            // 清除 5 秒定时器
            clearTimeout(autoNextQuestionTimer);
        
            // 检查当前题目是否已提交
            if (!isSubmitted) {
                // 如果未提交，先自动提交
                const currentCorrections = {
                    x: parseFloat(document.getElementById('x').value),
                    y: parseFloat(document.getElementById('y').value),
                    z: parseFloat(document.getElementById('z').value)
                };
                
                calculateSimulatedValues(kkk=false);
            }
            
            // 进入下一题
            if (currentQuestion < totalQuestions) {
                currentQuestion++;
                if(currentQuestion==totalQuestions){
                    this.disabled = true;
                }
                displayQuestion();
            } else {
                alert("已完成所有" + totalQuestions + "道题目！");
                this.disabled = true;
                document.getElementById('submit-btn').disabled = true;
                clearInterval(timerInterval);
                
                // 添加继续练题的按钮
                const continueButton = document.createElement('button');
                continueButton.textContent = "继续练题";
                continueButton.addEventListener('click', function() {
                    this.remove(); // 移除继续练题按钮
                    document.getElementById('next-btn').disabled = false;
                    document.getElementById('submit-btn').disabled = false;
                    restartQuestions();
                });
                document.body.appendChild(continueButton);
            }
        });
        
        // 重置所有状态并重新开始
        function restartQuestions() {
            currentQuestion = 1;
            history.length = 0; // 清空历史记录
            updateHistoryDisplay();
            displayQuestion();
        }
        
        // 初始显示
        displayQuestion();
    </script>
</body>
</html>

